/**
 * @author Tobias Boehm
 *
 * 16.05.2011
 */
package org.anddev.andengine.extension.tbsengine.message.client.preparematch;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;

import org.anddev.andengine.extension.tbsengine.message.ICopyable;
import org.anddev.andengine.extension.tbsengine.player.BasePlayer;

/**
 * This client message should be used to request a player change (join)
 * on a specific player slot.
 * 
 * @author Tobias Boehm
 *
 */
public class ClientSlotChangePlayerRequestMessage extends AbsClientSlotChangeRequestMessage implements ICopyable<ClientSlotChangePlayerRequestMessage> {

	private UUID mNewPlayerID = null;
	
		
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.multiplayer.protocol.adt.message.IMessage#getFlag()
	 */
	@Override
	public short getFlag() {
		
		return FLAG_CLIENT_SLOT_CHANGE_PLAYER_REQUEST;
	}

	@Override
	protected void onReadTransmissionClientSlotRequestData(
			DataInputStream pDataInputStream) throws IOException {
		
		this.mNewPlayerID = UUID.fromString(pDataInputStream.readUTF());
	}

	@Override
	protected void onWriteTransmissionClientSlotRequestData(
			DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeUTF(this.mNewPlayerID.toString());
	}

	/**
	 * @return the mNewPlayerID
	 */
	public UUID getNewPlayerID() {
		return mNewPlayerID;
	}

	/**
	 * @param mNewPlayerID the mNewPlayerID to set
	 */
	public void setNewPlayer(final BasePlayer pNewPlayer) {
		this.mNewPlayerID = pNewPlayer.getPlayerID();
	}

	@Override
	public ClientSlotChangePlayerRequestMessage copy() {
		
		final ClientSlotChangePlayerRequestMessage copy = new ClientSlotChangePlayerRequestMessage();
		
		copy.mMatchID = this.mMatchID;
		copy.mNewPlayerID = this.mNewPlayerID;
		copy.mPlayerID = this.mPlayerID;
		copy.mSlotID = this.mSlotID;
		
		return copy;
	}
}
